home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 2
/
SPACE - Library 2 - Volume 1.iso
/
apps
/
104
/
applic
/
atconv.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-02-20
|
2KB
|
97 lines
/*
atconv.c
program to translate ATASCII to ASCII or vice-versa.
call:
atconv filename
function: program translates all occurrences of 0x9b to
ox0d,0x0a and all occurrences of 0x0a to 0x9b.
Occurrences of 0x0d in the input are ignored.
The result of this translation is that files in
ATASCII are readable in ASCII and files in ASCII
are readable in ATASCII.
warnings: This program writes a temporary file "xyzzy.tmp"
which replaces the original file upon completion.
If the user wishes to retain the original file, a copy
should be made beforehand.
author: Bruce D. Nelson
*/
#include <stdio.h>
#include <osbind.h>
main (argc, argv)
int argc;
char *argv[];
{
int c1,dtabuff[22],whway;
long l,len;
FILE *fp1,*fp2;
if (argc < 2) {
printf("Usage: atconv filename\n");
exit();
}
if ((fp1 = fopen (argv[1], "br")) == NULL) {
printf ("Can't open %s\n",argv[1]);
exit();
}
if ((fp2 = fopen ("xyzzy.tmp", "bw")) == NULL) {
printf ("Can't open xyzzy.tmp");
exit();
}
Fsetdta (dtabuff);
Fsfirst (argv[1],0);
len = *(long *)(dtabuff+13);
whway = 0; /* indicates which way the translation was assumed */
for (l=0;l<len;l++){
c1 = fgetc(fp1);
switch (c1){
case 0x9b:{
whway = 1;
wputc(0x0d,fp2);
wputc(0x0a,fp2);
break;
}
case 0x0d:{
break;
}
case 0x0a:{
whway = 2;
wputc(0x9b,fp2);
break;
}
default:{
wputc(c1,fp2);
break;
}
} /* end switch */
}/* end for */
fclose (fp1);
fclose (fp2);
Fdelete(argv[1]);
Frename(0,"xyzzy.tmp",argv[1]);
if (whway == 1) printf ("%s converted from ATASCII to ASCII",argv[1]);
if (whway == 2) printf ("%s converted from ASCII to ATASCII",argv[1]);
}
wputc (c,f) /* fputc with error handling */
int c;
FILE *f;
{
if ((fputc(c,f))==EOF){
printf ("End of file on temp file\n");
exit();
}
}